package ProductionConsumption;

public class ProductionAConsumption {
    public static void main(String[] args) {
        Supermarket market = new Supermarket();

        // 2个生产者线程
        Thread p1 = new Thread(new Producer(market, 1));
        Thread p2 = new Thread(new Producer(market, 2));
        // 3个消费者线程
        Thread c1 = new Thread(new Consumer(market, 1));
        Thread c2 = new Thread(new Consumer(market, 2));
        Thread c3 = new Thread(new Consumer(market, 3));

        p1.start();
        p2.start();
        c1.start();
        c2.start();
        c3.start();

        // 等待所有线程结束
        try {
            p1.join();
            p2.join();
            c1.join();
            c2.join();
            c3.join();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }

        System.out.println("所有线程执行完毕");
    }
}
